package com.feihao.zhou.demoAnno;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TestDemoAnno {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException {
        //1.反射获取PrintString对象：
        Class<?> aClass = Class.forName("com.feihao.zhou.demoAnno.PrintString");

        //创建PrintString对象：
        PrintString printString  = (PrintString) aClass.newInstance();

        //2.获取aClsss对象中的所有方法：
        Method[] methods = aClass.getDeclaredMethods();

        //判断方法中有没有注解：
        for (Method method : methods) {
            if (method.isAnnotationPresent(Test.class)){
                //有注解则执行：
                method.setAccessible(true);
                method.invoke(printString);
            }
        }
    }
}
